package com.huluobo.base.net

import com.blankj.utilcode.BuildConfig
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
import java.sql.Time
import java.util.concurrent.TimeUnit

/**
 *  Created by LC on 2024/8/20.
 */
private val clientSign by lazy {
    OkHttpClient.Builder()
        .readTimeout(30, TimeUnit.SECONDS)
        .writeTimeout(30, TimeUnit.SECONDS)
        .connectTimeout(30, TimeUnit.SECONDS)
        .apply {
            if (BuildConfig.DEBUG) {
                addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            }
        }
        .addInterceptor(SignInterceptor())
        .build()
}

private val clientToken by lazy {
    OkHttpClient.Builder()
        .readTimeout(30, TimeUnit.SECONDS)
        .writeTimeout(30, TimeUnit.SECONDS)
        .connectTimeout(30, TimeUnit.SECONDS)
        .apply {
            if (BuildConfig.DEBUG) {
                addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            }
        }
        .addInterceptor(TokenInterceptor())
        .build()
}

val retrofitSign by lazy {
    Retrofit.Builder()
        .baseUrl(Const.baseUrl)
        .client(clientSign)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
}

val retrofitToken by lazy {
    Retrofit.Builder()
        .baseUrl(Const.baseUrl)
        .client(clientToken)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
}

inline fun <reified T> getServiceToken() = retrofitToken.create(T::class.java)
inline fun <reified T> getServiceSign() = retrofitSign.create(T::class.java)
